﻿#pragma once

#include "PlayerObject.h"
#include "../../Shared/Data/Stat.h"
#include "../../Shared/Enums.h"
#include "../../Shared/BaseStats.h"
#include "../../Shared/Data/ItemData.h"
#include "../../Shared/Data/ClientData.h"
#include "../../Shared/Data/IntelligentCreatureData.h"
#include "MapObject.h"
#include "../../Shared/ServerPackets.h"
#include <vector>
#include <algorithm>
#include <limits>

using namespace Client::MirScenes;
namespace S = ServerPackets;

namespace Client::MirObjects
{
    class UserObject : public PlayerObject
    {
    public:
        unsigned int Id = 0;

        int HP = 0, MP = 0;

        int AttackSpeed = 0;

        Stats *Stats;

        int CurrentHandWeight = 0, CurrentWearWeight = 0, CurrentBagWeight = 0;

        long long Experience = 0, MaxExperience = 0;

        bool TradeLocked = false;
        unsigned int TradeGoldAmount = 0;
        bool AllowTrade = false;

        bool RentalGoldLocked = false;
        bool RentalItemLocked = false;
        unsigned int RentalGoldAmount = 0;

        SpecialItemMode ItemMode = static_cast<SpecialItemMode>(0);

        BaseStats *CoreStats = new BaseStats(0);


        std::vector<UserItem*> Inventory = std::vector<UserItem*>(46), Equipment = std::vector<UserItem*>(14), Trade = std::vector<UserItem*>(10), QuestInventory = std::vector<UserItem*>(40);
        int BeltIdx = 6;
        bool HasExpandedStorage = false;
        DateTime ExpandedStorageExpiryTime;

        std::vector<ClientMagic*> Magics = std::vector<ClientMagic*>();
        std::vector<ItemSets*> ItemSets = std::vector<ItemSets*>();
        std::vector<EquipmentSlot> MirSet = std::vector<EquipmentSlot>();

        std::vector<ClientIntelligentCreature*> IntelligentCreatures = std::vector<ClientIntelligentCreature*>(); //IntelligentCreature
        IntelligentCreatureType SummonedCreatureType = IntelligentCreatureType::None; //IntelligentCreature
        bool CreatureSummoned = false; //IntelligentCreature
        int PearlCount = 0;

        std::vector<ClientQuestProgress*> CurrentQuests = std::vector<ClientQuestProgress*>();
        std::vector<int> CompletedQuests = std::vector<int>();
        std::vector<ClientMail*> Mail = std::vector<ClientMail*>();

        ClientMagic *NextMagic;
        Point *NextMagicLocation;
        MapObject *NextMagicObject;
        MirDirection NextMagicDirection = static_cast<MirDirection>(0);
        QueuedAction *QueuedAction;

        virtual ~UserObject()
        {
            delete Stats;
            delete CoreStats;
            delete NextMagic;
            delete NextMagicLocation;
            delete NextMagicObject;
            delete QueuedAction;
        }

        UserObject(unsigned int objectID);

        void Load(S::UserInformation *info);

        void SetSlots(S::UserSlotsRefresh *p);

        void SetLibraries() override;

        void SetEffects() override;

        void RefreshStats();

    private:
        void RefreshLevelStats();

        void RefreshBagWeight();

        void RefreshEquipmentStats();


        void RefreshSocketStats(UserItem *equipItem);

        void RefreshItemSetStats();

        void RefreshMirSetStats();

        void RefreshSkills();

        void RefreshBuffs();

    public:
        void RefreshGuildBuffs();

        void RefreshStatCaps();

        void BindAllItems();


        ClientMagic *GetMagic(Spell spell);


        void GetMaxGain(UserItem *item);
    private:
        int FreeSpace(std::vector<UserItem*> &array);

    public:
        void SetAction() override;
        void ProcessFrames() override;

        void ClearMagic();
    };
}

